/**
 * 用户profile
 */
var UserProfileViewerDialog = (function(){
        
    var userProfileDialogTmp = [
        '<div class="userProfileViewer">',
            '<div class="userProfileIcon">',
                '<img class="userProfileIconImg" src="<%= o.icon ? ujs.browser.loc.addQuery(o.icon, {w:200}) : ujs.getConfigRes("defUserIcon") %>" />',
            '</div>',
            '<div class="userProfileSummary">',
                '<h4 class="userProfileName"><%=o.name%></h4>',
                '<div class="userProfileProperties">',
                    '<div class="userProfilePropertyItem">',
                        '<label class="userProfilePropertyName" lan="lbl.account"></label>',
                        '<label class="userProfilePropertyValue"><%=o.account%></label>',
                    '</div>',
                    '<div class="userProfilePropertyItem">',
                        '<label class="userProfilePropertyName" lan="lbl.desp"></label>',
                        '<label class="userProfilePropertyValue"><%=o.desc || o.desp || o.description%></label>',
                    '</div>',
                    '<div class="userProfilePropertyItem dis" style="display:none">',
                        '<label class="userProfilePropertyName" lan="lbl.distance"></label>',
                        '<label class="userProfilePropertyValue"><%=o.dis%>(km)</label>',
                    '</div>',
                '</div>',
            '</div>',
        '</div>'
    ].join('');
    
    var _UserProfileViewerDialog = function(cfg){
        var _this = this;        
        var perm = this.config['perm'];        
        var buttons = [ perm['chat'] && !ujs.util.session.isCurrentUser(_this.config['user']['id']) ? {
            props : 'chat|Message',                    
            handler : function($btnObj){
                var uid = _this.config['user']['id'];
                var singleChat = page.chatGroupStore.getSingleChatByUser(uid);                    
                if(singleChat){
                    sessionList.startSession(singleChat['id']);
                    _this.close();
                } else {           
                    page.biz.createChatGroup(
                        Object.toFormData({
                            chat : JSON.stringify({
                                type : 'singlechat',
                                uids : [uid]
                            })
                        }), 
                        function(msg){                            
                            //add local
                            page.biz.addChatGroupLocal(msg);
                            _this.close();
                            sessionList.startSession(msg['te']['id']);                            
                        }
                    );
                }                    
            }
        } : undefined];
        
        if(this.config['kick']){
            buttons.push({
                props : 'hammer|Kick Out',                    
                handler : function($btnObj){   
                    bubble.confirm(lan('app.im.participant.kickOutTip', this.config['user']['name']), function(){
                       $.ajax({
                            type : 'delete',
                            url : _this.config['kick'],
                            success : function(){
                                if(Type.isFunction(_this.config['afterKick'])){
                                    _this.config['afterKick']();
                                }
                                _this.close();
                            }
                        }); 
                    });                            
                }
            });
        }
        
        this.setProps({            
            size : {
                width : 500,
                height : 350
            }, 
            buttons : buttons,
            toolbarStyle : {
                textAlign : 'center'
            }
        });
        
        //添加userProfile表单.
        this.addDialogContent(function($dialogContent) {
            $dialogContent.html(tmpl(userProfileDialogTmp, _this.config['user']));
            lan.parse($dialogContent);
            if(!Type.isUndefined(_this.config['user']['dis'])){
                $dialogContent.find('.userProfilePropertyItem.dis').show();
            }            
        });
                        
    }.extend(ujs.ui.Dialog);
    
    return _UserProfileViewerDialog;    
})();